library(tidyverse)
library(agricolae)
library(cowplot)认识常见试验布置
均以二因素试验设计为例
加载运行环境
完全随机试验设计
trt <- expand.grid(A=c("A1","A2","A3"),B=c("B1","B2","B3"),Block=1:3) %>%
mutate(trt=sprintf("%s%s",A,B))
rc <- expand.grid(rr=1:9,cc=1:3)
designDT <- trt %>%
add_column(seed=rnorm(n = nrow(.))) %>%
arrange(seed) %>% add_column(rc)
G1 <- ggplot(designDT,aes(x=cc,y=rr))+
geom_raster(aes(fill=trt))+
geom_text(aes(label=trt))+
theme_void()+
theme(legend.position = "none",strip.text=element_blank())
G1
随机区组试验设计
design <- design.ab(trt=c(3,3),r=3,design="rcbd")
designDT <- design$book %>% mutate(color=sprintf("A%sB%s",A,B))
rc <- expand.grid(rr=1:3,cc=1:3,b=1:3)
designDT <- designDT %>% add_column(rc)
G2 <- ggplot(designDT,aes(x=rr,y=cc))+
facet_grid(block~.)+
geom_raster(aes(fill=color))+
geom_text(aes(label=color))+
theme_void()+
theme(legend.position = "none",strip.text=element_blank())
G2
裂区试验设计
A <- sprintf("A%d",1:3)
B <- sprintf("B%d",1:3)
design <-design.split(A,B,3)
rc <- expand.grid(rr=1:3,cc=1:3,b=1:3)
designDT <- design$book %>% add_column(rc) %>%
mutate(color=sprintf("%s%s",A,B))
G5 <- ggplot(designDT,aes(x=rr,y=cc))+
facet_grid(block~.)+
geom_raster(aes(fill=color))+
geom_text(aes(label=color))+
theme_void()+
theme(legend.position = "none",strip.text=element_blank())
G5
条状试验设计
A <- sprintf("A%d",1:3)
B <- sprintf("B%d",1:3)
block <- 3
design <- design.strip(A,B,block,serie=2)
rc <- expand.grid(rr=1:3,cc=1:3,b=1:3)
designDT <- design$book %>% add_column(rc) %>%
mutate(color=sprintf("%s%s",A,B))
G4 <- ggplot(designDT,aes(x=rr,y=cc))+
facet_grid(block~.)+
geom_raster(aes(fill=color))+
geom_text(aes(label=color))+
theme_void()+
theme(legend.position = "none",strip.text=element_blank())
G4
伪试验设计
trt <- expand.grid(A=c("A1","A2","A3"),
B=c("B1","B2","B3"),block=1:3) %>%
mutate(trt=sprintf("%s%s",A,B))
G0 <- ggplot(trt,aes(x=A,y=B))+
facet_grid(block~.)+
geom_raster(aes(fill=trt))+
geom_text(aes(label=trt))+
theme_void()+
theme(legend.position = "none",strip.text=element_blank())
G0
常见试验设计对比
cowplot::plot_grid(G1,G2,NULL,NULL,G5,G4,ncol = 2,rel_heights = c(1, 0.1, 1),
labels = c("a","b","","","c","d"),hjust = 0)